package top.heue.temp.app

import android.os.Environment
import androidx.annotation.IntDef
import com.hjq.toast.Toaster
import top.heue.utils.v
import java.io.File

object Values {
    val app get() = AppModel.app

    //崩溃捕捉数据
    val TAG_ERROR_PID by v
    val TAG_ERROR by v

    //文件路径参数
    const val PATH_NONE = 0
    const val PATH_PRIVATE = 1
    const val PATH_EX_PRIVATE = 2
    const val PATH_STORAGE = 3

    @IntDef(PATH_NONE, PATH_PRIVATE, PATH_EX_PRIVATE, PATH_STORAGE)
    @Retention(AnnotationRetention.SOURCE)
    annotation class PathSelect

    /**获取给定名字在预设目录的File，支持以`/`分割的路径*/
    fun getDirOfPath(
        path: String,
        @PathSelect select: Int = PATH_NONE,
        isCache: Boolean = false
    ): File {
        val file = when (select) {
            PATH_PRIVATE -> {
                if (isCache) File(app.cacheDir, path) else File(app.filesDir, path)
            }

            PATH_EX_PRIVATE -> {
                if (isCache) File(app.externalCacheDir, path)
                else File(app.getExternalFilesDir(null), path)

            }

            PATH_STORAGE -> {
                val ext = Environment.getExternalStorageDirectory()
                File(ext, path)
            }

            else -> {
                File(path)
            }
        }
        if (!file.exists()) file.mkdirs()
        return file
    }
}

typealias T = Toaster

